package com.basic.business.pathRel.controller;


import java.util.List;
import java.io.IOException;

import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import com.basic.common.annotation.FileExport;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import org.springframework.web.bind.annotation.*;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.enums.BusinessType;
import com.basic.business.pathRel.domain.TPathRel;
import com.basic.business.pathRel.service.ITPathRelService;

/**
 * 路径关系Controller
 * 
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/pathRel")
public class TPathRelController extends BaseController
{
    @Resource
    private ITPathRelService tPathRelService;

    /**
     * 查询路径关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:pathRel:list')")
    @GetMapping("/list")
    public AjaxResult list(TPathRel tPathRel)
    {
        List<TPathRel> list = tPathRelService.getList(tPathRel);
        return success(list);
    }

    /**
     * 导出路径关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:pathRel:export')")
    @Log(title = "路径关系", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "路径关系.xlsx")
    @PostMapping("/export")
    public String export(TPathRel tPathRel) throws IOException
    {
        List<TPathRel> list = tPathRelService.getList(tPathRel);
        return EasyExcelUtils.excelExport(TPathRel.class,"路径关系数据", list);
    }

    /**
     * 获取路径关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:pathRel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tPathRelService.get(id));
    }

    /**
     * 新增路径关系
     */
    @PreAuthorize("@ss.hasPermi('business:pathRel:add')")
    @Log(title = "路径关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPathRel tPathRel)
    {
        if (!tPathRelService.checkPathRelNameUnique(tPathRel)) {
            return error("名称已存在，请重新输入");
        }

        return toAjax(tPathRelService.insert(tPathRel));
    }

    /**
     * 修改路径关系
     */
    @PreAuthorize("@ss.hasPermi('business:pathRel:edit')")
    @Log(title = "路径关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPathRel tPathRel)
    {
        if (!tPathRelService.checkPathRelNameUnique(tPathRel)) {
            return error("名称已存在，请重新输入");
        }
        return toAjax(tPathRelService.update(tPathRel));
    }

    /**
     * 删除路径关系
     */
    @PreAuthorize("@ss.hasPermi('business:pathRel:remove')")
    @Log(title = "路径关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tPathRelService.deleteByIds(ids));
    }

    /**
     * 刷新缓存
     */
    @PreAuthorize("@ss.hasPermi('business:pathRel:refreshCache')")
    @Log(title = "路径关系", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache()
    {
        tPathRelService.resetPathRelCache();
        return success();
    }

    /**
     * 状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:pathRel:changeStatus')")
    @Log(title = "路径关系", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tPathRelService.updateStatusByIds(ids, status));
    }
}
